package com.wits.qso.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import com.wits.platform.entity.BaseEntity;
import com.wits.platform.entity.User;

@Entity
@Table(name="qso_announce_h")
public class AnnounceH extends BaseEntity {

	private static final long serialVersionUID = 1L;

	private String id;
	/**公告人*/
	private User user;
	/**日期*/
	private String date;
	/**公告对象*/
	private Cls clsId;
	/**公告标题*/
	private String title;
	/**公告内容*/
	private String content;
	
	private boolean isAll;
	
	@Id
	@GenericGenerator(name = "idGen", 
					strategy = "com.wits.platform.common.id.generator.IDGenerator",
					parameters={ 
								@Parameter(name = "segment_value", value = "QSO_ANN_ID"), 
								@Parameter(name="table_name",value="wits_id_generator"),
								@Parameter(name="value_column_name",value="gen_value"),
								@Parameter(name="segment_column_name",value="gen_name"),
								@Parameter(name="segment_value_length",value="5"),
								@Parameter(name="sq_format",value="%03d"), 
								@Parameter(name="sq_prefix",value="ANNID") 
					})
	@GeneratedValue(generator = "idGen")
	@Column(name = "ann_id", nullable = false, insertable = true, updatable = false, length = 10)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "us_id_ann")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(name="date_ann")
	public String getDate() {
		return date;
	}
	
	public void setDate(String date) {
		this.date = date;
	}

	@ManyToOne
	@JoinColumn(name="ann_class")
	public Cls getClsId() {
		return clsId;
	}

	public void setClsId(Cls clsId) {
		this.clsId = clsId;
	}

	@Column(name="ann_title")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name="ann_ctnt")
	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	@Column(name="isall")
	public boolean isAll() {
		return isAll;
	}

	public void setAll(boolean isAll) {
		this.isAll = isAll;
	}

	@Override
	public String display() {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public String toString(){
		return "{\"id\":\"" + this.id 
				+ "\",\"username\":\"" + this.user.getUserNameC()
				+ "\",\"annclass\":\"" + (this.isAll?"所有班级":this.clsId.getClsTitle())
				+ "\",\"title\":\"" + this.title
				+ "\",\"content\":\"" + this.content
				+ "\",\"date\":\"" + this.date
				+ "\" }";
	}

}
